@using MudBlazor.Internal
@namespace MudBlazor
@inherits MudFormComponent<T, string>
@typeparam T


@code
{

    protected virtual RenderFragment InputContent =>
        @<MudTextField @ref="_inputReference" @attributes="UserAttributes" Label="@Label" @bind-Text="@Text" HelperText="@HelperText" Variant="@Variant" ReadOnly="@(!Editable || ReadOnly)" T="string" Style="@Style"
                    @onclick="(() => { if (!Editable) ToggleState(); })" OnAdornmentClick="ToggleState" Disabled="@Disabled" Adornment="@Adornment"
                    AdornmentIcon="@AdornmentIcon" AdornmentColor="@AdornmentColor" IconSize="@IconSize" Margin="@Margin"
                    Required="@Required" RequiredError="@RequiredError" Error="@Error" ErrorText="@ErrorText"/>;

    protected virtual RenderFragment PickerContent => null;

    protected virtual RenderFragment Render =>
    @<CascadingValue Value="@this" IsFixed="true">
        <div class="@PickerClass">
            @if (PickerVariant != PickerVariant.Static)
            {
                <CascadingValue Name="Standalone" Value="false" IsFixed="true">
                    @InputContent
                </CascadingValue>
            }
            @if (IsOpen && PickerVariant == PickerVariant.Inline)
            {
               <div @ref="_pickerInlineRef" class="@PickerInlineClass">
                   <MudPaper @attributes="UserAttributes" Class="@PickerPaperClass" Elevation="@_pickerElevation" Square="@_pickerSquare">
                       <div class="@PickerContainerClass">
                           @PickerContent
                       </div>
                        @if (PickerActions != null)
                        {
                            <div class="@ActionClass">
                                @PickerActions
                            </div>
                        }
                   </MudPaper>
               </div>
            }
            else if (PickerVariant == PickerVariant.Static)
            {
               <MudPaper @attributes="UserAttributes" Class="@PickerPaperClass" Elevation="@_pickerElevation" Square="@_pickerSquare">
                   <div class="@PickerContainerClass">
                       @PickerContent
                   </div>
                    @if (PickerActions != null)
                    {
                        <div class="@ActionClass">
                            @PickerActions
                        </div>
                    }
               </MudPaper>
            }
            else if(IsOpen && PickerVariant == PickerVariant.Dialog)
            {
               <MudOverlay Visible="IsOpen" OnClick="CloseOverlay" DarkBackground="true" Class="mud-overlay-dialog">
                   <MudPaper @attributes="UserAttributes" Class="@PickerPaperClass" Elevation="@_pickerElevation" Square="@_pickerSquare">
                       <div class="@PickerContainerClass">
                           @PickerContent
                       </div>
                        @if (PickerActions != null)
                        {
                            <div class="@ActionClass">
                                @PickerActions
                            </div>
                        }
                   </MudPaper>
               </MudOverlay>
            }
        </div>
        @if (PickerVariant == PickerVariant.Inline)
        {
            <MudOverlay Visible="IsOpen" OnClick="CloseOverlay" LockScroll="false"/>
        }
    </CascadingValue>;
}


